import java.awt.*;
import java.awt.event.ActionEvent;

import javax.swing.*;
/*
 * Created by JFormDesigner on Wed Jun 06 17:51:38 PDT 2012
 */



/**
 * @author David Jaenisch
 */
public class StoryPanel extends JPanel {
	
	public Story story;
	
	public StoryPanel() {
		initComponents();
	}
	
	public StoryPanel(Story story){
		initComponents();
		setStory(story);
	}

	private void initComponents() {
		// JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
		// Generated using JFormDesigner Evaluation license - David Jaenisch
		titleLabel = new JLabel();
		centralPanel = new JPanel();
		picture = new JLabel();
		button1 = new JButton();
		button2 = new JButton();
		button3 = new JButton();
		textRegion = new JLabel();

		//======== this ========
		setBackground(new Color(0, 102, 51));

		// JFormDesigner evaluation mark
		setBorder(new javax.swing.border.CompoundBorder(
			new javax.swing.border.TitledBorder(new javax.swing.border.EmptyBorder(0, 0, 0, 0),
				"JFormDesigner Evaluation", javax.swing.border.TitledBorder.CENTER,
				javax.swing.border.TitledBorder.BOTTOM, new java.awt.Font("Dialog", java.awt.Font.BOLD, 12),
				java.awt.Color.red), getBorder())); addPropertyChangeListener(new java.beans.PropertyChangeListener(){public void propertyChange(java.beans.PropertyChangeEvent e){if("border".equals(e.getPropertyName()))throw new RuntimeException();}});

		setLayout(new GridBagLayout());
		((GridBagLayout)getLayout()).columnWidths = new int[] {606, 0, 0};
		((GridBagLayout)getLayout()).rowHeights = new int[] {0, 0, 0, 0, 0, 0, 0};
		((GridBagLayout)getLayout()).columnWeights = new double[] {0.0, 0.0, 1.0E-4};
		((GridBagLayout)getLayout()).rowWeights = new double[] {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0E-4};

		//---- titleLabel ----
		titleLabel.setText("Title");
		titleLabel.setHorizontalAlignment(SwingConstants.CENTER);
		titleLabel.setForeground(Color.white);
		add(titleLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH,
			new Insets(10, 0, 0, 0), 0, 0));

		//======== centralPanel ========
		{
			centralPanel.setLayout(new FlowLayout());

			//---- picture ----
			picture.setMaximumSize(new Dimension(500, 500));
			picture.setMinimumSize(new Dimension(500, 500));
			picture.setPreferredSize(new Dimension(500, 500));
			picture.setIcon(null);
			picture.setHorizontalAlignment(SwingConstants.CENTER);
			centralPanel.add(picture);
		}
		add(centralPanel, new GridBagConstraints(0, 1, 1, 4, 0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH,
			new Insets(0, 0, 0, 0), 0, 0));

		//---- button1 ----
		button1.setMaximumSize(new Dimension(100, 100));
		button1.setMinimumSize(new Dimension(100, 100));
		button1.setPreferredSize(new Dimension(100, 100));
		button1.setText("Button 1");
		add(button1, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH,
			new Insets(0, 0, 0, 10), 0, 0));

		//---- button2 ----
		button2.setPreferredSize(new Dimension(100, 100));
		button2.setMinimumSize(new Dimension(100, 100));
		button2.setMaximumSize(new Dimension(100, 100));
		button2.setText("2");
		add(button2, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH,
			new Insets(50, 0, 0, 10), 0, 0));

		//---- button3 ----
		button3.setPreferredSize(new Dimension(100, 100));
		button3.setMinimumSize(new Dimension(100, 100));
		button3.setMaximumSize(new Dimension(100, 100));
		button3.setText("3");
		add(button3, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0,
			GridBagConstraints.NORTH, GridBagConstraints.HORIZONTAL,
			new Insets(50, 0, 0, 10), 0, 0));

		//---- textRegion ----
		textRegion.setText("Lorem ipsum");
		textRegion.setMaximumSize(new Dimension(500, 200));
		textRegion.setMinimumSize(new Dimension(500, 200));
		textRegion.setPreferredSize(new Dimension(500, 200));
		textRegion.setVerticalAlignment(SwingConstants.TOP);
		textRegion.setBackground(new Color(204, 204, 204));
		textRegion.setOpaque(true);
		add(textRegion, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0,
			GridBagConstraints.CENTER, GridBagConstraints.BOTH,
			new Insets(10, 10, 10, 0), 0, 0));
		// JFormDesigner - End of component initialization  //GEN-END:initComponents
	}

	// JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
	// Generated using JFormDesigner Evaluation license - David Jaenisch
	private JLabel titleLabel;
	private JPanel centralPanel;
	private JLabel picture;
	private JButton button1;
	private JButton button2;
	private JButton button3;
	private JLabel textRegion;
	// JFormDesigner - End of variables declaration  //GEN-END:variables

	public void setStory(Story story){

		this.story = story;
		if(story != null){
			setLabelText(story.label);
			setTextBody(story.mainTextBody);
			
			setButton1Story(story.story1Name, story.story1);
			setButton2Story(story.story2Name, story.story2);
			setButton3Story(story.story3Name, story.story3);
		
		}
		
	}
	
	public void setLabelText(String text){
		button2.setEnabled(false);
		titleLabel.setText(text);
	}
	
	public void setTextBody(String text){
		button2.setEnabled(false);
		textRegion.setText(text);
	}
	
	public void setButton1Story(String text, Story story){
		button1.setAction(new StoryPanelAction(text,story));
		button1.setEnabled(story != null);
	}
	
	public void setButton2Story(String text, Story story){
		button2.setAction(new StoryPanelAction(text,story));
		button2.setEnabled(story != null);
	}
	
	public void setButton3Story(String text, Story story){
		button3.setAction(new StoryPanelAction(text,story));
		button3.setEnabled(story != null);
	}
	
	private class StoryPanelAction extends AbstractAction{
		
		private Story story;
		
		public StoryPanelAction(String text, Story story){
			this.story = story;
			putValue(NAME, text);
			
		}
		
		@Override
		public void actionPerformed(ActionEvent arg0) {
			setStory(story);
			
			
		}
		
	}
}
